<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\ApiController;
use App\Http\Controllers\Controller;
use App\Models\Banner;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;

class BannerController extends ApiController
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        $limit = $request->input('limit', 10);
        $type = $request->input('type', 1);
        $list = Banner::limit($limit)
            ->orderBy('sort', 'desc')
            ->get()
            ->map(function($item) {
                return [
                    'title' => $item->title,
                    'img_url' => Storage::url($item->img),
                ];
            });
        return $this->okReturn($list);
    }
}
